package cn.tedu.ivos.user.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.dto.UserQuery;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import cn.tedu.ivos.user.service.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@RestController
@Tag(name = "用户模块", description = "用户管理相关接口")
@RequestMapping("v1/user/")
public class UserController {
    @Autowired
    UserService userService;

    @Operation(summary = "用户登录")
    @PostMapping("login")
    @ApiOperationSupport(order = 10)
    public JsonResult login(@RequestBody @Validated UserLoginParam userLoginParam) {
        log.debug("开始处理用户登录的请求..." + userLoginParam);
        //
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @Operation(summary = "查询用户")
    @GetMapping("select")
    @ApiOperationSupport(order = 20)
    public JsonResult selectUser(UserQuery userQuery) {
        log.debug("开始处理查询用户请求..." + userQuery);
        List<UserVO> list = userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @Operation(summary = "保存用户")
    @PostMapping("save")
    @ApiOperationSupport(order = 30)
    public JsonResult save(@Validated UserSaveParam userSaveParam) {
        log.debug("开始处理保存用户请求..." + userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @Operation(summary = "重置密码")
    @PostMapping("update/password/{userId}")
    @ApiOperationSupport(order = 40)
    public JsonResult resetPassword(@PathVariable Long userId) {
        log.debug("开始处理重置密码请求..." + userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }

    @Operation(summary = "重置状态")
    @PostMapping("update/status/{userId}/{status}")
    @ApiOperationSupport(order = 50)
    public JsonResult resetStatus(@PathVariable Long userId, @PathVariable String status) {
        log.debug("开始处理重置状态请求..." + userId + " " + status);
        userService.resetStatus(userId, status);
        return JsonResult.ok();
    }

    @Operation(summary = "删除用户")
    @PostMapping("delete/{userId}")
    @ApiOperationSupport(order = 60)
    public JsonResult delete(@PathVariable Long userId) {
        log.debug("开始处理删除用户请求..." + userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }


}




















